package com.forever7776.life.web.controller.life.m;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.forever7776.life.core.common.vo.UserBlogSearchVO;
import com.forever7776.life.core.entity.Follow;
import com.forever7776.life.core.entity.blog.Blog;
import com.forever7776.life.core.service.IFollowService;
import com.forever7776.life.core.service.blog.IBlogService;
import com.forever7776.life.core.service.sys.ISysUserService;
import com.forever7776.life.web.controller.BaseController;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 我的关注
 *
 * @author kz
 * @date 2018年02月10日
 */
@Controller
@RequestMapping(value = "/m/follow")
public class MyFollowController extends BaseController {

    @Autowired
    private IFollowService iFollowService;
    @Autowired
    private ISysUserService iSysUserService;

    @RequestMapping
    public String index() {
        return USER_VIEW_PAGE_PATH + "follow/index";
    }

    @RequestMapping("/list")
    @ResponseBody
    public JSONObject list(String username) {
        JSONObject result = new JSONObject();
        String searchUserId = null;
        if (StringUtils.isNotEmpty(username)) {
            searchUserId = iSysUserService.selectUserIdByUsername(username);
        }
        Page<Follow> page = iFollowService.selectAll(new Page<Follow>(pageNumber, pageSize), getUserId(), searchUserId);
        result.put("page", page);
        return result;
    }

    /**
     * 查询博客数量
     *
     * @return
     */
    @RequestMapping(value = "/count", method = RequestMethod.GET)
    @ResponseBody
    public JSONObject count() {
        JSONObject result = new JSONObject();
        result.put("count", iFollowService.selectCount(new EntityWrapper<Follow>().eq("user_id", getUserId())));
        return result;
    }
}
